package cn.crce.cloud9.simple;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileWriter;

/**
 * @author OnCloud9
 * @description
 * @project NRCE-TEST
 * @date 2022年09月10日 上午 09:18
 */
public class Case17 implements ActionListener {

    JTextArea ta;
    JFrame f ;
    JLabel label;
    JButton bt;

    public static void main(String args[ ]){
        Case17 t = new Case17();
        t.go();
    }

    void go(){
        f = new JFrame("Save data");
        label = new JLabel("请输入需要保存的文本：");
        ta = new JTextArea(3,20);
        bt = new JButton("保存");
        //*********Found********
        f.add(label,BorderLayout.NORTH);
        f.add(ta, BorderLayout.CENTER);
        f.add(bt,BorderLayout.SOUTH);
        //*********Found********
        bt.addActionListener(this);
        f.setSize(400,400);
        f.pack( );
        f.setVisible(true) ;
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public void actionPerformed(ActionEvent event){
        try{
            FileWriter out = new FileWriter("out.txt");
            String str = ta.getText();
            //*********Found********
            out.write(str);
            out.close();
        } catch( Exception e){
        }
    }
}
